<?php /*a:1:{s:66:"D:\work\web\write_play_1\application\admin\view\user\register.html";i:1554799494;}*/ ?>

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<script src="/static/js/jquery-3.3.1.min.js"></script>
	<script src="/static/js/jsencrypt.min.js"></script>
	<script src="/static/layui-v2.4.5/layui//layui.js"></script>
	<link rel="stylesheet" href="/static/layui-v2.4.5/layui//css/layui.css" type="text/css" />
	<style type="text/css">
		.disp_none{
			font-size:10px;
			color:red;
			display: none;
		}
		.a{
			margin-bottom: 10px;
			height: 15px;
		}
		
	</style>
</head>

<body>
<form  class="layui-form" style="width: 300px;margin:10% auto;">
<div class="layui-form-item" style="margin-bottom: 0px;">
<input type="text" name="mobile"  f-name="validate" class="layui-input"   placeholder="请输入手机号">

</div>
<div class="a">
<label id="mobile_error" class="disp_none"></label>
</div>
<div class="layui-form-item" style="margin-bottom: 0px;">
<input type="password" name="password" f-name="validate" class="layui-input"  placeholder="请输入密码">

</div>
<div class="a">
<label id="password_error" class="disp_none"></label>
</div>
<div class="layui-form-item" style="margin-bottom: 0px;">
<input type="password" f-name="validate" name="repassword" class="layui-input" placeholder="请输入确认密码">
</div>
<div class="a">
<label id="repassword_error" class="disp_none"></label>
</div>



<div class="layui-form-item">
<input type="button" id="register" class="layui-btn layui-btn-normal" style="width: 300px;" value="注册">
</div>
<div class="layui-form-item">
<input type="button" onclick="window.location.href='login'" class="layui-btn layui-btn-primary" style="width: 300px;" value="已有账号，直接登录">
</div>

</form>

</body>

<script type="text/javascript">
	$('input[f-name="validate"]').focus(function(){
		var events = $._data($(this)[0], "events");
		if(events && !events['blur'])		
			$(this).bind('blur',function(){validate(this)});
		
		if($(this).prop('name') == 'password')
			$('#password_error').text('6-20个字符,由字母,数字和符号2种以上组成').css({'display':'block','color':'gray'});
		else
			$('#'+$(this).prop('name')+'_error').css('display','none');
	})

	$('#register').click(function(){
		$('input[f-name="validate"]').blur();
		num = 0;
		$(".disp_none").each(function(){
			if($(this).css('display') == 'none'){
				num++;
			}
		})
		
		if(num == 3){
			var rsa = new JSEncrypt();
			rsa.setPublicKey("-----BEGIN PUBLIC KEY-----\
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3WvMS6rbQLOxcwwGOYSxoRIv1\
XRlUs+CW21Q/+SfX3xnMmh72jObiUUV243Ilrnxp91+nmf4o7OZbp/EvjlkJRNvz\
+9HxZsr1ZVb3TafSAUvUanrsLkHhfAJHQQexX1Tpd4yUWLWxPkvVR975hNy7mOSF\
SBNNqbSEiFhTg2SyuwIDAQAB\
-----END PUBLIC KEY-----\
",'10001');
			var pwd = rsa.encrypt($('input[name="password"]').val());
			console.log(pwd);
			var mobile = $('input[name="mobile"]').val();
			$.post('register',{'mobile':mobile,'password':pwd},function(res){
					if(!res){
						for(var key in res){
							show_error($('#'+key+'_error'),res[key]);
						}
					}else{
						window.location.href = 'login';
					}
					
			})
		}
	})

	$(document).keydown(function(event){
　　　		　if(event.keyCode == '13' && $(':focus').prop('id') != 'register')
			$('#register').click();
　　   });

	function show_error(e,text){
		e.text(text).css({'display':'block','color':'red'});
	}

	function validate(e){
		var name = $(e).prop('name'),
		value = $(e).val();
		switch(name){
			case 'mobile':
			{
				if( value== '')
					show_error($('#mobile_error'),'请输入手机号!');
				else if(!(/^1[34578]\d{9}$/.test(value)))
					show_error($('#mobile_error'),'手机号格式错误!');
				else{
					$.post('register',{'mobile':value},function(res){
						if(typeof(res.mobile) != 'undefined')
							show_error($('#mobile_error'),res['mobile']);
					})
				}
			}
			break;
			case 'password':
			{
				if( value== '')
					show_error($('#password_error'),'请输入密码!');
				else if((/^[0-9]+$/.test(value)))
					show_error($('#password_error'),'密码不能为纯数字!');
				else if(!(/^.{6,20}$/.test(value)))
					show_error($('#password_error'),'请输入6-20位密码!');
				else if((/^[a-zA-Z]+$/.test(value)))
					show_error($('#password_error'),'密码不能为纯字母!');
				else if(/^[^\da-zA-Z]+$/.test(value))
					show_error($('#password_error'),'密码不能为纯符号!');
				else if($('input[name="repassword"]').val() != '' && value != $('input[name="repassword"]').val()){
					show_error($('#repassword_error'),'两次密码不一致!');	
					$('#password_error').css('display','none');
				}else if(/\s+/.test(value))
					show_error($('#password_error'),'密码由字符、数字和符号组成!');
				else if($('input[name="repassword"]').val() == value){
					$('#repassword_error').css('display','none');
					$('#password_error').css('display','none');
				}
				else
					$('#password_error').css('display','none');
			}
			break;	
			case 'repassword':
			{
				var password = $('input[name="password"]').val();
				if( password== ''){
					show_error($('#password_error'),'请输入密码!');
					return;
				}
				else if(value == '')
					show_error($('#repassword_error'),'请输入确认密码!');
				else if(value != password )
					show_error($('#repassword_error'),'两次密码不一致!');
			}
			break;
		}
		
		$(e).unbind('blur');
	}
	
	$('input[f-name="validate"]').bind('blur',function(){validate(this)});
</script>
</html>

